package com.jzo2o.orders.manager.service.client;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.jzo2o.api.customer.AddressBookApi;
import com.jzo2o.api.customer.dto.response.AddressBookResDTO;
import groovy.util.logging.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;



/**
 * TODO   调用customer的客户端
 *  @AUTHOR 正缘寓君
 *  @Dare 2024/12/6 16:33
 */
@Component  //配置类
@Slf4j
public class CustomerClient {
    @Autowired
    private AddressBookApi addressBookApi;
    @SentinelResource(value = "getAddressBookDetail",fallback = "detailFallback",blockHandler = "detailBlockHandler")
   //- value: 用于定义资源的名称，即 Sentinel 会对该资源进行流量控制和熔断降级。
    //- fallback ：非限流、熔断等导致的异常执行的降级方法
    //- blockHandler :触发限流、熔断时执行的降级方法
    public AddressBookResDTO dto (Long id){
        System.out.print("根据id查询地址簿,id:{}"+id);
        //调用其他微服务方法
        AddressBookResDTO detail = addressBookApi.detail(id);
        return  detail;
    }
    //执行异常走
    public  AddressBookResDTO  detailFallback(Long id,Throwable throwable){
        System.out.print("非限流、熔断等导致的异常执行的降级方法，id:{},throwable:"+id+throwable);
         return  null;
    }

}